﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

    public class Elevator
    {
        int minFloor;
        int maxFloor;
        int currentFloor;
        string doorStatus = "closed";
        string movingDirection = "stationary"; 

        ArrayList commands;

        public Elevator(int minimumFloor, int maximumFloor)
        {
            minFloor = minimumFloor;
            maxFloor = maximumFloor;
            currentFloor = minimumFloor;
            commands = new ArrayList(); 
        }

        public void addNewCommand(String command)
        {
            if (commands.Contains(command))
            {            
            }
            else 
            {
                commands.Add(command);
                //MessageBox.Show("command added");
            }
            //commands.Sort(); 
        }

        public void removeCommand(String command)
        {
            commands.Remove(command); 
        }

        public String getNextCommand()
        {
            if (commands.Count != 0)
            {
                return commands[0].ToString();
            }
            else
            {
                return ""; 
            }
        }

        public void sortCommands()
        {
            if (this.getMovingDirection().Equals("waiting"))
            {
            }
            else if (this.getMovingDirection().Equals("moving up"))
            {
                commands.Reverse();
            }
            else if (this.getMovingDirection().Equals("moving down"))
            {
                commands.Sort();
            }
        }

        public int getCurrentFloor()
        {
            return currentFloor;
        }

        public void setCurrentFloor(int floor)
        {
            currentFloor = floor;
        }

        public int getMinFloor()
        {
            return minFloor;
        }

        public int getMaxFloor()
        {
            return maxFloor;
        }

        public void setDoors(String status)
        {
            doorStatus = status;
        }

        public string getDoorStatus()
        {
            return doorStatus;
        }

        public void setMovingDirection(String status)
        {
            movingDirection = status;
        }

        public string getMovingDirection()
        {
            return movingDirection; 
        }
    }
}
